merge with xen-unstable.hg
authorawilliam@xenbuild.aw <awilliam@xenbuild.aw>
Tue, 18 Apr 2006 15:35:40 +0000 (09:35 -0600)
committerawilliam@xenbuild.aw <awilliam@xenbuild.aw>
Tue, 18 Apr 2006 15:35:40 +0000 (09:35 -0600)
1  2 
tools/ioemu/vl.c
tools/libxc/xc_ia64_stubs.c

Simple merge
index d9372ae5a5788e5af41fe43e1e5da7f03d0f6ed7,335fd5ec7173836450e758dfc3a6bdec5d45cbb7..15fcbb8122c381569b3ab3493d82bb08e988ebd1
@@@ -48,62 -48,35 +48,62 @@@ xc_plan9_build(int xc_handle
      PERROR("xc_plan9_build not implemented\n");
      return -1;
  }
-   */
 +/*  
 +    VMM uses put_user to copy pfn_list to guest buffer, this maybe fail,
 +    VMM don't handle this now.
 +    This method will touch guest buffer to make sure the buffer's mapping
 +    is tracked by VMM,
++ */
  
  int xc_ia64_get_pfn_list(int xc_handle,
-                          uint32_t domid, 
-                          unsigned long *pfn_buf, 
+                          uint32_t domid,
+                          unsigned long *pfn_buf,
                           unsigned int start_page,
                           unsigned int nr_pages)
  {
      dom0_op_t op;
 -    int ret;
 -    unsigned long max_pfns = ((unsigned long)start_page << 32) | nr_pages;
 +    int num_pfns,ret;
 +    unsigned int __start_page, __nr_pages;
 +    unsigned long max_pfns;
 +    unsigned long *__pfn_buf;
 +    __start_page = start_page;
 +    __nr_pages = nr_pages;
 +    __pfn_buf = pfn_buf;
 +  
 +    while(__nr_pages){
 +        max_pfns = ((unsigned long)__start_page << 32) | __nr_pages;
 +        op.cmd = DOM0_GETMEMLIST;
 +        op.u.getmemlist.domain   = (domid_t)domid;
 +        op.u.getmemlist.max_pfns = max_pfns;
 +        op.u.getmemlist.buffer   = __pfn_buf;
 +
 +        if ( (max_pfns != -1UL)
-                   && mlock(__pfn_buf, __nr_pages * sizeof(unsigned long)) != 0 )
++            && mlock(__pfn_buf, __nr_pages * sizeof(unsigned long)) != 0 )
 +        {
 +            PERROR("Could not lock pfn list buffer");
 +            return -1;
-         }    
++        }
  
 -    op.cmd = DOM0_GETMEMLIST;
 -    op.u.getmemlist.domain   = (domid_t)domid;
 -    op.u.getmemlist.max_pfns = max_pfns;
 -    op.u.getmemlist.buffer   = pfn_buf;
 +        ret = do_dom0_op(xc_handle, &op);
  
 -    if ( (max_pfns != -1UL)
 -        && mlock(pfn_buf, nr_pages * sizeof(unsigned long)) != 0 )
 -    {
 -        PERROR("Could not lock pfn list buffer");
 -        return -1;
 -    }
 +        if (max_pfns != -1UL)
-               (void)munlock(__pfn_buf, __nr_pages * sizeof(unsigned long));
++            (void)munlock(__pfn_buf, __nr_pages * sizeof(unsigned long));
  
 -    ret = do_dom0_op(xc_handle, &op);
 +        if (max_pfns == -1UL)
 +            return 0;
 +        
 +        num_pfns = op.u.getmemlist.num_pfns;
 +        __start_page += num_pfns;
 +        __nr_pages -= num_pfns;
 +        __pfn_buf += num_pfns;
  
-         if (ret < 0) 
-             // dummy write to make sure this tlb mapping is tracked by VMM 
 -    if (max_pfns != -1UL)
 -        (void)munlock(pfn_buf, nr_pages * sizeof(unsigned long));
 -
 -    return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
++        if (ret < 0)
++            // dummy write to make sure this tlb mapping is tracked by VMM
 +            *__pfn_buf = 0;
-         else 
-             return nr_pages;    
-     }    
++        else
++            return nr_pages;
++    }
 +    return nr_pages;
  }
  
  long xc_get_max_pages(int xc_handle, uint32_t domid)
@@@ -147,18 -120,11 +147,18 @@@ error_out
  }
  
  
--#define HOB_SIGNATURE 0x3436474953424f48 // "HOBSIG64"
- #define GFW_HOB_START         ((4UL<<30)-(14UL<<20))    //4G -14M
- #define GFW_HOB_SIZE          (1UL<<20)              //1M
 -#define GFW_HOB_START    ((4UL<<30)-(14UL<<20))    //4G -14M
 -#define GFW_HOB_SIZE     (1UL<<20)              //1M
 -#define MEM_G   (1UL << 30)
 -#define MEM_M   (1UL << 20)
++#define HOB_SIGNATURE         0x3436474953424f48        // "HOBSIG64"
++#define GFW_HOB_START         ((4UL<<30)-(14UL<<20))    // 4G - 14M
++#define GFW_HOB_SIZE          (1UL<<20)                 // 1M
 +#define RAW_GFW_START_NR(s)   ((s) >> PAGE_SHIFT)
 +#define RAW_GFW_HOB_START_NR(s)                \
 +        (RAW_GFW_START_NR(s) + ((GFW_HOB_START - GFW_START) >> PAGE_SHIFT))
 +#define RAW_GFW_IMAGE_START_NR(s,i)            \
 +        (RAW_GFW_START_NR(s) + (((GFW_SIZE - (i))) >> PAGE_SHIFT))
 +#define RAW_IO_PAGE_START_NR(s)                \
 +        (RAW_GFW_START_NR(s) + (GFW_SIZE >> PAGE_SHIFT))
 +#define RAW_STORE_PAGE_START_NR(s)             \
 +        (RAW_IO_PAGE_START_NR(s) + (IO_PAGE_SIZE >> PAGE_SHFIT))
  
  typedef struct {
      unsigned long signature;
@@@ -348,12 -313,11 +348,12 @@@ int build_hob (void* hob_buf, unsigned 
      return 0;
  
  err_out:
-     return -1;  
+     return -1;
  }
  
- static int 
+ static int
 -load_hob(int xc_handle, uint32_t dom, void *hob_buf)
 +load_hob(int xc_handle, uint32_t dom, void *hob_buf,
-        unsigned long dom_mem_size)
++         unsigned long dom_mem_size)
  {
      // hob_buf should be page aligned
      int hob_size;
      }
  
      nr_pages = (hob_size + PAGE_SIZE -1) >> PAGE_SHIFT;
-     
      return xc_ia64_copy_to_domain_pages(xc_handle, dom,
 -            hob_buf, GFW_HOB_START, nr_pages );
 +            hob_buf, RAW_GFW_HOB_START_NR(dom_mem_size), nr_pages );
  }
  
  #define MIN(x, y) ((x) < (y)) ? (x) : (y)
@@@ -620,9 -589,8 +620,9 @@@ static int setup_guest(  int xc_handle
      }
  
      /* Load guest firmware */
-     if( xc_ia64_copy_to_domain_pages( xc_handle, dom, 
+     if( xc_ia64_copy_to_domain_pages( xc_handle, dom,
 -            image, 4*MEM_G-image_size, image_size>>PAGE_SHIFT)) {
 +            image, RAW_GFW_IMAGE_START_NR(dom_memsize, image_size),
 +            image_size>>PAGE_SHIFT)) {
          PERROR("Could not load guest firmware into domain");
          goto error_out;
      }
      }
  
      /* Retrieve special pages like io, xenstore, etc. */
 -    if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array, IO_PAGE_START>>PAGE_SHIFT, 2) != 2 )
 +    if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array,
-                               RAW_IO_PAGE_START_NR(dom_memsize), 2) != 2 )
++                              RAW_IO_PAGE_START_NR(dom_memsize), 2) != 2 )
      {
          PERROR("Could not get the page frame list");
          goto error_out;